package com.buffer.agent.controller;


import com.buffer.agent.service.QwenAgentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


// HTTP 测试接口，浏览器直接访问
@RestController
@RequestMapping("/agent")
public class AgentController {
    @Autowired
    private QwenAgentService qwenAgentService;
    
    /**
     * 智能体对话接口
     * 访问示例：http://localhost:8080/agent/chat?userId=test001&query=查询当前时间
     * @param userId 用户ID（区分不同会话）
     * @param query 用户问题
     * @return 智能体响应
     */
    @GetMapping("/chat")
    public String chat(
            @RequestParam() String userId,
            @RequestParam() String query
    ) {
        try {
            return qwenAgentService.processRequest(userId, query);
        } catch (Exception e) {
            return "接口调用失败：" + e.getMessage();
        }
    }
}
